<template>
  <el-form ref="editFormRef" :model="form" v-loading="loading">
    <pub-edit-description :ndColumns="1">
      <pub-edit-description-item :span="1" label="真实姓名" required>
        <el-form-item prop="realName" :rules="$formRules.input">
          <pub-input v-model="form.realName" />
        </el-form-item>
      </pub-edit-description-item>
      <pub-edit-description-item :span="1" label="登录账号" required>
        <el-form-item prop="userName" :rules="$formRules.input">
          <pub-input v-model="form.userName" />
        </el-form-item>
      </pub-edit-description-item>
      <pub-edit-description-item :span="1" label="手机号码">
        <el-form-item prop="telephone" :rules="$formRules.phoneOrNumNotRequired">
          <pub-input v-model="form.telephone" />
        </el-form-item>
      </pub-edit-description-item>
    </pub-edit-description>
  </el-form>
  <div class="dialog-footer-btn">
    <el-button type="default" @click="close()">取消</el-button>
    <el-button type="primary" @click="submitForm(editFormRef)" v-prevent-repeat-click>保存</el-button>
  </div>
</template>


<script setup>
const emit = defineEmits(['close', 'submitForm'])
const props = defineProps({
  editData: {
    type: Object,
    default() {
      return {}
    }
  },
  isEdit: Boolean
})
const editFormRef = ref()
const loading = ref(false)
const form = ref({})


onMounted(() => {
  if (props.isEdit) {
    form.value = JSON.parse(JSON.stringify(props.editData))
  }
})

const change = () => {
  if (form.status == 1) {
    form.status = 0
  } else {
    form.status = 1
  }
}
const close = () => {
  emit('close')
}
const loadClose = () => {
  loading.value = false
}
const submitForm = editFormRef => {
  editFormRef.validate(valid => {
    if (valid) {
      loading.value = true
      form.value.customType = 2
      emit('submitForm', form.value)
    }
  })
}
</script>

<style scoped>
.align-center {
  align-items: center;
}
/* 弹窗提交时loading样式需占满整个弹窗 */
.el-loading-parent--relative {
  position: inherit !important;
}
</style>
